package top.datacluster.basic.algorithm.leetcode.dynamic;

public class LeetCode197 {

    public boolean oneEditAway(String first, String second) {
        if (Math.abs(first.length() - second.length()) > 1){
            return false;
        }else if (first.length() == second.length()){
            int i = 0;
            int count = 0;
            while (i < first.length()){
                if (first.charAt(i) != second.charAt(i)){
                    count++;
                }
                i++;
            }
            return count <= 1;
        }else{
            int i = 0;
            while (i < first.length() && i < second.length()){
                if (first.charAt(i) == second.charAt(i)){
                    i++;
                }else{
                    break;
                }
            }

            return true;
        }

    }
}
